
/*
 * @(#)MaintCalendarRecordSearchForm.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
     * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.calendar.web;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.dcivision.calendar.bean.CalendarRecord;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.web.AbstractSearchForm;

/**
  MaintCalendarRecordSearchForm.java
  This class is the for web form purpose.
  @author      Tony Chen
  @company     DCIVision Limited
  @creation date   07/12/2003
  @version     $Revision: 1.4 $
 */

public class MaintCalendarRecordSearchForm   extends AbstractSearchForm {

  public static final String REVISION = "$Revision: 1.4 $";

  private String ownerID = null;
  private String sourceID = null;
  private String companyID = null;
  private String updateAlertID = null;
  private String sourceType = null;
  private String activityType = null;
  private String eventType = null;
  private String title = null;
  private String detail = null;
  private String purpose = null;

  private String startDate = null;
  private String startHour = null;
  private String startMinute = null;
  private String endDate = null;
  private String endHour = null;
  private String endMinute = null;

  private String datetime = null;
  private String endtime = null;
  private String isWholeDay = null;
  private String priority = null;
  private String status = null;
  private String venue = null;
  private String shareType = null;
  private String alertType = null;
  private String reminderAmount = null;
  private String reminderType = null;
  private String report = null;
  private String isRecurrence = null;
  private String[] userIDsToShare = null;
  private String[] groupIDsToShare = null;
  private String[] roleIDsToShare = null;
  private String needReply = null;
  private String recurStartDate = null;
  private String recurEndDate = null;



  private String repeatTimes = null;

  private String recurType = null;

  private String repeatOn = null;

  private String repeatType = null;

  private String repeatTypeDay = null;

  private String occurType = null;

  private String occurMonth = null;

  private String occurWeekDay = null;

  private String[] notifyWay = new String[0];
  private String emailReminder = null;
  private String systemReminder = null;

  /** Holds value of property updateDateFrom.  */
  private String accessDateFrom;

  /** Holds value of property updateDateTo.  */
  private String accessDateTo;
  private String accessDateType;
  private String dateTime;

  /** Holds value of property periodType.   */
  private String periodType="month";
  private String varAry=null;
  private String[] userRecords=new String[0];
  private String[] userGroups=new String[0];
  private String[] userRoles=new String[0];


  private String creatorID = null;

  public String getCreatorID () {
    return this.creatorID;
  }

  public void setCreatorID (String creatorID) {
    this.creatorID = creatorID;
  }



  public String[] getUserRecords(){
    return this.userRecords;
  }

  public void setUserRecords(String[] userRecords){
    this.userRecords = userRecords;
  }

  public String[] getUserGroups(){
    return this.userGroups;
  }

  public void setUserGroups(String[] userGroups){
   this.userGroups = userGroups;
  }


  public String[] getUserRoles(){
    return this.userRoles;
  }

  public void setUserRoles(String[] userRoles){
    this.userRoles = userRoles;
  }

  public String getVarAry(){
      return this.varAry;
  }
  public void setVarAry(String varAry){
      this.varAry=varAry;
  }

  /**
   * Getter for property periodType.
   * @return Value of property periodType.
   */
  public String getPeriodType() {
    return this.periodType;
  }
  public void setPeriodType(String periodType){
    this.periodType = periodType;
  }


  public String getDateTime() {
    Calendar cal = Calendar.getInstance();
    if (Utility.isEmpty(periodType)) {
      return dateTime;
    }
    else if ("week".equals(periodType)) {
      cal.add(Calendar.DATE, 7 - cal.get(Calendar.DAY_OF_WEEK));
    }
    else if ("month".equals(periodType)) {
      cal.add(Calendar.MONTH, 1);
      cal.set(Calendar.DATE, 0);
    }
    else if ("full".equals(periodType)) {
      return null;
    }
    cal.set(Calendar.AM_PM, Calendar.PM);
    cal.set(Calendar.HOUR, 11);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    return TextUtility.formatDate(cal.getTime(),
				  SystemParameterFactory.
				  getSystemParameter(SystemParameterConstant.
	DB_DATETIME_FORMAT));
  }

  /**
   * Setter for property updateDateTo.
   * @param updateDateTo New value of property updateDateTo.
   */
  public void setDatetime(String dateTime) {
    this.dateTime = dateTime;
  }

  public MaintCalendarRecordSearchForm() {
    super();
    this.setSortAttribute("ID");
    this.setSortOrder("ASC");
  }

  public String getOwnerID() {
    return (this.ownerID);
  }

  public void setOwnerID(String ownerID) {
    this.ownerID = ownerID;
  }

  public String getSourceID() {
    return (this.sourceID);
  }

  public void setSourceID(String sourceID) {
    this.sourceID = sourceID;
  }

  public String getCompanyID() {
    return (this.companyID);
  }

  public void setCompanyID(String companyID) {
    this.companyID = companyID;
  }

  public String getUpdateAlertID() {
    return (this.updateAlertID);
  }

  public void setUpdateAlertID(String updateAlertID) {
    this.updateAlertID = updateAlertID;
  }

  public String getSourceType() {
    return (this.sourceType);
  }

  public void setSourceType(String sourceType) {
    this.sourceType = sourceType;
  }

  public String getActivityType() {
    return (this.activityType);
  }

  public void setActivityType(String activityType) {
    this.activityType = activityType;
  }

  public String getEventType() {
    return (this.eventType);
  }

  public void setEventType(String eventType) {
    this.eventType = eventType;
  }

  public String getTitle() {
    return (this.title);
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getDetail() {
    return (this.detail);
  }

  public void setDetail(String detail) {
    this.detail = detail;
  }

  public String getPurpose() {
    return (this.purpose);
  }

  public void setPurpose(String purpose) {
    this.purpose = purpose;
  }

  public void setStartDate(String startDate) {
      this.startDate = startDate;
  }

  public String getStartDate() {
    Calendar cal = Calendar.getInstance();
    if(Utility.isEmpty(periodType)){
      return startDate;
    }else if("week".equals(periodType)){
      cal.add(Calendar.DATE,1-cal.get(Calendar.DAY_OF_WEEK));
    }else if("month".equals(periodType)){
      cal.set(Calendar.DATE,1);
    }else if("full".equals(periodType)){
      return null;
    }

    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return TextUtility.formatDate(cal.getTime(), SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT));

  }

  public void setStartHour(String startHour) {
    GregorianCalendar gCal = new GregorianCalendar() ;
    int hour=gCal.getActualMinimum(GregorianCalendar.HOUR_OF_DAY);
    startHour=Integer.toString(hour);
    this.startHour = startHour;
  }

  public String getStartHour() {
      return startHour;
  }

  public void setStartMinute(String startMinute) {
      this.startMinute = startMinute;
  }

  public String getStartMinute() {
      return startMinute;
  }

  public void setEndHour(String endHour) {
      GregorianCalendar gCal = new GregorianCalendar() ;
      int hour=gCal.getActualMaximum(GregorianCalendar.HOUR_OF_DAY);
      endHour=Integer.toString(hour);
      this.endHour = endHour;
  }

  public void setEndDate(String endDate) {
      this.endDate = endDate;
  }

  public String getEndDate() {
    Calendar cal = Calendar.getInstance();
    if(Utility.isEmpty(periodType)){
      return endDate;
    }else if("week".equals(periodType)){
      cal.add(Calendar.DATE,7-cal.get(Calendar.DAY_OF_WEEK));
    }else if("month".equals(periodType)){
      cal.add(Calendar.MONTH,1);
      cal.set(Calendar.DATE,0);
    }else if("full".equals(periodType)){
      return null;
    }
    cal.set(Calendar.AM_PM, Calendar.PM);
    cal.set(Calendar.HOUR, 11);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    return TextUtility.formatDate(cal.getTime(), SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT));

  }

  public String getEndHour() {
      return endHour;
  }
  public void setEndMinute(String endMinute) {
      this.endMinute = endMinute;
  }

  public String getEndMinute() {
      return endMinute;
  }
  public void setEndtime(String endtime) {
    this.endtime = endtime;
  }

  public String getEndtime() {
      return this.endtime;
  }

  public String getIsWholeDay() {
    return (this.isWholeDay);
  }

  public void setIsWholeDay(String isWholeDay) {
    this.isWholeDay = isWholeDay;
  }

  public String getPriority() {
    return (this.priority);
  }

  public void setPriority(String priority) {
    this.priority = priority;
  }

  public String getStatus() {
    return (this.status);
  }

  public void setStatus(String status) {
    this.status = status;
  }

  public String getVenue() {
    return (this.venue);
  }

  public void setVenue(String venue) {
    this.venue = venue;
  }

  public String getShareType() {
    return (this.shareType);
  }

  public void setShareType(String shareType) {
    this.shareType = shareType;
  }

  public String getAlertType() {
    return (this.alertType);
  }

  public void setAlertType(String alertType) {
    this.alertType = alertType;
  }

  public String getReminderAmount() {
    return (this.reminderAmount);
  }

  public void setReminderAmount(String reminderAmount) {
    this.reminderAmount = reminderAmount;
  }

  public String getReminderType() {
    return (this.reminderType);
  }

  public void setReminderType(String reminderType) {
    this.reminderType = reminderType;
  }

  public String getReport() {
    return (this.report);
  }

  public void setReport(String report) {
    this.report = report;
  }

  public String getIsRecurrence() {
    return (this.isRecurrence);
  }

  public void setIsRecurrence(String isRecurrence) {
    this.isRecurrence = isRecurrence;
  }

  public void setUserIDsToShare(String[] userIDsToShare) {
    this.userIDsToShare = userIDsToShare;
  }

  public String[] getUserIDsToShare() {
    return this.userIDsToShare;
  }

  public void setGroupIDsToShare(String[] groupIDsToShare) {
    this.groupIDsToShare = groupIDsToShare;
  }

  public String[] getGroupIDsToShare() {
    return this.groupIDsToShare;
  }

  public void setRoleIDsToShare(String[] roleIDsToShare) {
    this.roleIDsToShare = roleIDsToShare;
  }

  public String[] getRoleIDsToShare() {
    return this.roleIDsToShare;
  }

  public void setNeedReply(String needReply) {
    this.needReply = needReply;
  }

  public String getNeedReply() {
    return this.needReply;
  }

  public void setRecurStartDate(String recurStartDate) {
    this.recurStartDate = recurStartDate;
  }

  public String getRecurStartDate() {
    return recurStartDate;
  }

  public void setRecurEndDate(String recurEndDate) {
    this.recurEndDate = recurEndDate;
  }

  public String getRecurEndDate() {
    return this.recurEndDate;
  }

  public void setRepeatTimes(String repeatTimes) {
    this.repeatTimes = repeatTimes;
  }

  public String getRepeatTimes() {
    return this.repeatTimes;
  }

  public void setRecurType(String recurType) {
    this.recurType = recurType;
  }

  public String getRecurType() {
    return this.recurType;
  }

  public void setRepeatOn(String repeatOn) {
    this.repeatOn = repeatOn;
  }

  public String getRepeatOn() {
    return this.repeatOn;
  }

  public void setRepeatType(String repeatType) {
    this.repeatType = repeatType;
  }

  public String getRepeatType() {
    return this.repeatType;
  }

  public void setRepeatTypeDay(String repeatTypeDay) {
    this.repeatTypeDay = repeatTypeDay;
  }

  public String getRepeatTypeDay() {
    return this.repeatTypeDay;
  }

  public void setOccurType(String occurType) {
    this.occurType = occurType;
  }

  public String getOccurType() {
    return this.occurType;
  }

  public void setOccurMonth(String occurMonth) {
    this.occurMonth = occurMonth;
  }

  public String getOccurMonth() {
    return this.occurMonth;
  }

  public void setOccurWeekDay(String occurWeekDay) {
    this.occurWeekDay = occurWeekDay;
  }

  public String getOccurWeekDay() {
    return this.occurWeekDay;
  }

  public void setNotifyWay(String[] notifyWay) {
    this.notifyWay = notifyWay;
  }

  public String[] getNotifyWay() {
    return this.notifyWay;
  }

  public void setEmailReminder(String emailReminder) {
    this.emailReminder = emailReminder;
  }

  public String getEmailReminder() {
    return this.emailReminder;
  }

  public void setSystemReminder(String systemReminder) {
    this.systemReminder = systemReminder;
  }

  public String getSystemReminder() {
    return this.systemReminder;
  }

  public ActionErrors validate(ActionMapping mapping,
                               HttpServletRequest request) {
    return super.validate(mapping, request);
  }

  public void reset(ActionMapping mapping, HttpServletRequest request) {
    super.reset(mapping, request);
    this.setOwnerID(null);
    this.setSourceID(null);
    this.setCompanyID(null);
    this.setUpdateAlertID(null);
    this.setSourceType(null);
    this.setActivityType(null);
    this.setEventType(null);
    this.setTitle(null);
    this.setDetail(null);
    this.setPurpose(null);
    this.setIsWholeDay(null);
    this.setPriority(null);
    this.setStatus(null);
    this.setVenue(null);
    this.setShareType(null);
    this.setAlertType(null);
    this.setReminderAmount(null);
    this.setReminderType(null);
    this.setReport(null);
    this.setIsRecurrence(null);
    this.setUserIDsToShare(null);
    this.setGroupIDsToShare(null);
    this.setRoleIDsToShare(null);
    this.setNeedReply(null);
    this.setRecurStartDate(null);
    this.setRecurEndDate(null);
    this.setRepeatTimes(null);
    this.setRecurType(null);
    this.setRepeatType(null);
    this.setRepeatTypeDay(null);
    this.setOccurType(null);
    this.setOccurMonth(null);
    this.setOccurWeekDay(null);
    this.setNotifyWay(null);
    this.setEmailReminder(null);
    this.setSystemReminder(null);
  }

  public AbstractBaseObject getFormData() throws ApplicationException {
    CalendarRecord tmpCalendarRecord = new CalendarRecord();
    tmpCalendarRecord.setOwnerID(TextUtility.parseIntegerObj(this.getOwnerID()));
    tmpCalendarRecord.setSourceID(TextUtility.parseIntegerObj(this.getSourceID()));
    tmpCalendarRecord.setCompanyID(TextUtility.parseIntegerObj(this.
        getCompanyID()));
    tmpCalendarRecord.setUpdateAlertID(TextUtility.parseIntegerObj(this.
        getUpdateAlertID()));
    tmpCalendarRecord.setSourceType(this.getSourceType());
    tmpCalendarRecord.setActivityType(this.getActivityType());
    tmpCalendarRecord.setEventType(this.getEventType());
    tmpCalendarRecord.setTitle(this.getTitle());
    tmpCalendarRecord.setDetail(this.getDetail());
    tmpCalendarRecord.setPurpose(this.getPurpose());
    tmpCalendarRecord.setIsWholeDay(this.getIsWholeDay());
    tmpCalendarRecord.setPriority(this.getPriority());
    tmpCalendarRecord.setStatus(this.getStatus());
    tmpCalendarRecord.setVenue(this.getVenue());
    tmpCalendarRecord.setShareType(this.getShareType());
    tmpCalendarRecord.setAlertType(TextUtility.parseIntegerObj(this.
        getAlertType()));
    tmpCalendarRecord.setReminderAmount(TextUtility.parseIntegerObj(this.
        getReminderAmount()));
    tmpCalendarRecord.setReminderType(this.getReminderType());
    tmpCalendarRecord.setReport(this.getReport());
    tmpCalendarRecord.setIsRecurrence(this.getIsRecurrence());
    return tmpCalendarRecord;
  }

  public void setFormData(AbstractBaseObject baseObj) throws
      ApplicationException {
    CalendarRecord tmpCalendarRecord = (CalendarRecord) baseObj;
    this.setOwnerID(TextUtility.formatIntegerObj(tmpCalendarRecord.getOwnerID()));
    this.setSourceID(TextUtility.formatIntegerObj(tmpCalendarRecord.getSourceID()));
    this.setCompanyID(TextUtility.formatIntegerObj(tmpCalendarRecord.
        getCompanyID()));
    this.setUpdateAlertID(TextUtility.formatIntegerObj(tmpCalendarRecord.
        getUpdateAlertID()));
    this.setSourceType(tmpCalendarRecord.getSourceType());
    this.setActivityType(tmpCalendarRecord.getActivityType());
    this.setEventType(tmpCalendarRecord.getEventType());
    this.setTitle(tmpCalendarRecord.getTitle());
    this.setDetail(tmpCalendarRecord.getDetail());
    this.setPurpose(tmpCalendarRecord.getPurpose());
    this.setIsWholeDay(tmpCalendarRecord.getIsWholeDay());
    this.setPriority(tmpCalendarRecord.getPriority());
    this.setStatus(tmpCalendarRecord.getStatus());
    this.setVenue(tmpCalendarRecord.getVenue());
    this.setShareType(tmpCalendarRecord.getShareType());
    this.setAlertType(TextUtility.formatIntegerObj(tmpCalendarRecord.
        getAlertType()));
    this.setReminderAmount(TextUtility.formatIntegerObj(tmpCalendarRecord.
        getReminderAmount()));
    this.setReminderType(tmpCalendarRecord.getReminderType());
    this.setReport(tmpCalendarRecord.getReport());
    this.setIsRecurrence(tmpCalendarRecord.getIsRecurrence());
    this.setCreatorID(TextUtility.formatIntegerObj(tmpCalendarRecord.
        getCreatorID()));
  }


}
